package com.yanqu.road.server.cmd.wingroom.message;

import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.wingroom.WingRoomMessageMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2022/3/19 23:53
 */
@Cmd(code = GameProtocol.S_WING_ROOM_CROSS_NEW_MESSAGE, desc = "跨服来留言")
public class CrossNewMessageCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        WingRoomProto.NewMessageCrossReqMsg crossReqMsg = WingRoomProto.NewMessageCrossReqMsg.parseFrom(packet.getBytes());
        WingRoomProto.NewMessageRespMsg.Builder respMsg = WingRoomMessageMgr.newMessage(crossReqMsg.getOwnerUserId(), crossReqMsg.getContent(), crossReqMsg.getNoteStyle(),
                crossReqMsg.getGuestServerId(), crossReqMsg.getGuestUserId(), crossReqMsg.getRelativesIdsList());

        WingRoomProto.NewMessageRespCrossMsg.Builder respCrossMsg = WingRoomProto.NewMessageRespCrossMsg.newBuilder();
        respCrossMsg.setRespMsg(respMsg);
        respCrossMsg.setGuestServerId(crossReqMsg.getGuestServerId());
        respCrossMsg.setGuestUserId(crossReqMsg.getGuestUserId());
        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_WING_ROOM_NEW_MESSAGE_RESP, respCrossMsg);
        GamePlayerMgr.sendPacket(0, message);
    }
}
